package com.auxgroup.smarthome.business.vo;

import com.auxgroup.bridge.business.inner.vo.DeviceExportDataVo;
import com.auxgroup.smarthome.utils.NewDateUtils;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @Author: laiqiuhua.
 * @Date: 2017/9/21 15:24.
 */
public class DeviceExportTitleVo {
    private String mac;
    private String did;
    private String sn;
    private String online;
    private int meshLife;
    private String latestOnlineTime;

    public String getMac() {
        return mac;
    }

    public void setMac(String mac) {
        this.mac = mac;
    }

    public String getDid() {
        return did;
    }

    public void setDid(String did) {
        this.did = did;
    }

    public String getSn() {
        return sn;
    }

    public void setSn(String sn) {
        this.sn = sn;
    }

    public int getMeshLife() {
        return meshLife;
    }

    public String getOnline() {
        return online;
    }

    public void setOnline(String online) {
        this.online = online;
    }

    public void setMeshLife(int meshLife) {
        this.meshLife = meshLife;
    }


    public String getLatestOnlineTime() {
        return latestOnlineTime;
    }

    public void setLatestOnlineTime(String latestOnlineTime) {
        this.latestOnlineTime = latestOnlineTime;
    }

    public static DeviceExportTitleVo createExportData(DeviceExportDataVo exportDataVo) {
        DeviceExportTitleVo export = new DeviceExportTitleVo();
        export.setMac(exportDataVo.getMac());
        export.setDid(exportDataVo.getDid());
        long epoch = exportDataVo.getLatestOnlineTime() == null? 0L : exportDataVo.getLatestOnlineTime();
        LocalDateTime onlineTime = LocalDateTime.ofInstant(Instant.ofEpochSecond(epoch), NewDateUtils.getBeijingZoneId());
        export.setLatestOnlineTime(onlineTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
        export.setMeshLife(exportDataVo.getMeshLife());
        String onlinStr = exportDataVo.getOnline()? "在线" : "离线";
        export.setOnline(onlinStr);
        export.setSn(exportDataVo.getSn());
        return export;
    }
}
